package com.example.smartcity.ui.Tools;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import androidx.fragment.app.Fragment;


import java.util.Optional;

public abstract class BaseFragment extends Fragment {
    private Activity mActivity;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public abstract int getLayout();

    protected void initFragmentToolBar(String toolbarText,Boolean isShowHomeAsUp){
        ((BaseActivity) this.getActivity()).initToolBar(toolbarText,isShowHomeAsUp);
    }

    protected void hideToolbar(){
        ((BaseActivity)this.getActivity()).hideToolBar();
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        this.mActivity = ((Activity)context);
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    protected android.app.Activity getMyContext() {
        return Optional.ofNullable(((Activity) getActivity())).orElseGet(() -> mActivity);
    }
}
